package savantConn;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.Queue;
import javax.activation.MimetypesFileTypeMap;

public class FileTool {

  public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  //文件夹下文件
  public static void fileList(String dirPath) {
    File file = new File(dirPath);

    if (file.exists()) {
      File[] files = file.listFiles();
      for (File f : files) {
        System.out.println(f.getName());
        System.out.println(sdf.format(new Date(f.lastModified())));
        System.out.println(new MimetypesFileTypeMap().getContentType(f));//fileType
      }
    }
  }

  //文件夹下所有文件
  public static void allfileList(String dirPath) {
    File file = new File(dirPath);

    Queue<File> queue = new LinkedList<>();
    queue.offer(file);

    while (queue.size() > 0) {
      file = queue.poll();
      if (file.exists()) {
        File[] files = file.listFiles();
        for (File f : files) {
          System.out.println(f.getName());
          System.out.println(sdf.format(new Date(f.lastModified())));
          System.out.println(new MimetypesFileTypeMap().getContentType(f));//fileType
        }
      }
    }
  }
}
